用 C# 開發小時鐘,使用了 Timer、Label
這是個小範例,是使用 C# 寫個小時鐘,使用了 Timer 與 Label,先將這兩個控制項加入,而 label 是用來顯示時間,Timer 是用來定時重複更新時間
程式碼如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 100;
            timer1.Enabled = true;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString();
        }
    }
}
結果如下

請問若Label1.text要顯示的日期格式想自訂
該怎麼寫
可以將DateTime.Now做格式化再依需求設定Label